#!/bin/bash
#
# Copyright(c) 2012-2021 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause
#

# The line below specified that line under it should be used as the test's short description when launching test via run_tests script.
# The text should not be longer than 80 chars - if it is, the script will strip addititonal characters
# DESCRIPTION IO Class - setting and listing check with WLTH set

# Standard beginning for every test - get the main tests directory and
# link the cas_lib file for CAS API, then use "start_test $*" to pass params
# and do other necessary checks and setup.

# The line below says that this test should be included in BVT - it will be launched, when we use "./run_tests -b"
# USE_IN_BVT
# USE_IN_NIGHTLY

TESTS_DIR="$(dirname $0)/../"
. $TESTS_DIR/cas_lib
. $TESTS_DIR/io_class/cas_lib_io_class

start_test $*

# Check if current kernel supports write hints
KERNEL_VER_OPTION="4" KERNEL_MAJOR_OPTION="13" check_kernel_ver
if [ "$?" -ne 0 ] ; then
	end_test $CAS_TEST_NOT_RUN
fi

# Check if fio supports write hints
FIO_MAJOR_OPTION="3" FIO_MINOR_OPTION="13" check_fio_ver
if [ "$?" -ne 0 ] ; then
	end_test $CAS_TEST_NOT_RUN
fi

test_log_start

# Use CACHE_DEVICE and CORE_DEVICE provided by configuration file and remove partitions from those devices
TARGET_DEVICE_OPTION="$CACHE_DEVICE" remove_partitions
TARGET_DEVICE_OPTION="$CORE_DEVICE" remove_partitions

# Create 200M primary partition on CACHE_DEVICE
TARGET_DEVICE_OPTION="$CACHE_DEVICE" PARTITION_SIZE_OPTION="200M" PARTITION_IDS_OPTION="1" make_primary_partitions
# Create 400M primary partition on CORE_DEVICE
TARGET_DEVICE_OPTION="$CORE_DEVICE" PARTITION_SIZE_OPTION="400M" PARTITION_IDS_OPTION="1" make_primary_partitions

# Start cache
CACHE_ID_OPTION="1" CACHE_DEVICE_OPTION="${CACHE_DEVICE}-part1" start_cache

# Add core
CACHE_ID_OPTION="1" CORE_DEVICE_OPTION="${CORE_DEVICE}-part1" add_core

# Prepare IO class config with wlth specified
io_class_config_wlth

# Load config
CACHE_ID_OPTION="1" CSV_FILE=$(io_class_config_file) io_class_load

# Compare cache IO class config with generated one
CACHE_ID_OPTION="1" CSV_FILE=$(io_class_config_file) io_class_cmp

# Stop cache
CACHE_ID_OPTION="1" stop_cache

test_log_stop
end_test 0
